package com.pwt.scheduled;

import com.pwt.entity.*;
import com.pwt.model.CloudMessageModel;
import com.pwt.repository.*;
import com.pwt.utils.CloudHomeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author dw
 * @date 2022/1/19 14:14
 * @Description
 */
@Component
@Slf4j
public class CloudHomeScheduled {

    @Autowired
    private WERTEVARRepository wertevarRepository;
    @Autowired
    private ZzWatchChartsThread zzWatchChartsThread;


    public static Long newTime;

    public void init(){
        Date date = this.wertevarRepository.queryNewestWVDATZEIT();
        newTime = date == null ? System.currentTimeMillis() : date.getTime();
    }



//    @Scheduled(fixedRate  = 1000)
    public void cloudOnOkScheduled(){
        if(newTime == null)  init();
        List<WERTEVAR> list = wertevarRepository.queryAllByWVDATZEIT(new Date(newTime));
        zzWatchChartsThread.run(list);
//        更新1秒
        newTime = newTime + 1000;
    }


}
